package cn.wolfcode.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    /**
     * 获取传入天数的最后一刻
     */
    public static Date getEndDate(Date date) {
        if (date == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }

    /**
     * 获取两个Date对象之间的秒数
     * @param date1
     * @param date2
     * @return
     */
    public static long getDateBetween(Date date1, Date date2) {
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        return Math.abs(time1 - time2) / 1000;
    }
}
